package paolo.android.worldclock;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class TimeZoneEntry {
	private String id = "";

	TimeZoneEntry() {
		
	}
	
	TimeZoneEntry(String id) {
		this.id = id;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String toString() {
		return getId();
	}
	
	boolean alreadySaved(SQLiteDatabase db) {
		String args[] = {id};
		ContentValues cv = new ContentValues();
		
		cv.put("tzid", id);
		Cursor c = db.rawQuery("SELECT * FROM timezones WHERE tzid=?", args);
		
		if (c.getCount() == 0) {
			return false;
		}
		
		return true;
	}
	
	void save(SQLiteDatabase db) {
		ContentValues cv = new ContentValues();
		
		cv.put("tzid", id);
		db.insert("timezones", "tzid", cv);
	}
	
	void delete(SQLiteDatabase db) {
		String args[] = {id};
		ContentValues cv = new ContentValues();
		
		cv.put("tzid", id);
		db.delete("timezones", "tzid=?", args);
	}

	static Cursor getAll(SQLiteDatabase db) {
		return db.rawQuery("SELECT * FROM timezones", null);
	}
}